<!-- 课程管理(模块) => 课程列表(菜单) => 台账操作列(签到记录按钮) => 点击路由跳转 => 新页面台账操作列(学生签到明细) => 点开后展示此组件 -->
<template>
  <Dialog :title="t('signStudentLog.index.title')" v-model="dialogVisible" width="1400">
    <ContentWrap>
      <!-- 搜索工作栏 -->
      <el-form
        class="-mb-15px"
        :model="queryParams"
        ref="queryFormRef"
        :inline="true"
        label-width="68px"
      >
        <el-form-item :label="t('signStudentLog.fields.studentName')" prop="studentName">
          <el-input
            v-model="queryParams.studentName"
            :placeholder="t('common.inputTextPlaceholder') + t('signStudentLog.fields.studentName')"
            clearable
            @keyup.enter="handleQuery"
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item :label="t('signStudentLog.fields.studentCode')" prop="studentCode">
          <el-input
            v-model="queryParams.studentCode"
            :placeholder="t('common.inputTextPlaceholder') + t('signStudentLog.fields.studentCode')"
            clearable
            @keyup.enter="handleQuery"
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item>
          <el-button @click="handleQuery">
            <Icon icon="ep:search" class="mr-5px" />
            {{ t('common.search') }}
          </el-button>
          <el-button @click="resetQuery">
            <Icon icon="ep:refresh" class="mr-5px" />
            {{ t('common.reset') }}
          </el-button>
        </el-form-item>
      </el-form>
    </ContentWrap>

    <!-- 列表 -->
    <ContentWrap>
      <vxe-table
        id="iCourseSignStudentLog-table"
        v-loading="loading"
        :data="list"
        stripe
        :custom-config="vxeTableConfig"
        :column-config="{ resizable: true }"
        :size="vxeTableSize"
      >
        <vxe-column :title="t('common.index')" type="seq" field="seq" width="60" align="center" />
        <vxe-column
          :title="t('signStudentLog.fields.studentName')"
          field="studentName"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
        <vxe-column
          :title="t('signStudentLog.fields.studentCode')"
          field="studentCode"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
        <vxe-column
          :title="t('signStudentLog.fields.studentPhone')"
          field="studentPhone"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
        <vxe-column
          :title="t('signStudentLog.fields.signInStatus')"
          field="signInStatus"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        >
          <template #default="scope">
            <span v-if="scope.row.signInStatus === 0">{{ t('signStudentLog.fields.miss') }}</span>
            <span v-if="scope.row.signInStatus === 1">{{ t('signStudentLog.fields.normal') }}</span>
            <span v-if="scope.row.signInStatus === 2">{{ t('signStudentLog.fields.late') }}</span>
          </template>
        </vxe-column>
        <vxe-column
          :title="t('signStudentLog.fields.signOutStatus')"
          field="signOutStatus"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        >
          <template #default="scope">
            <span v-if="scope.row.signOutStatus === 0">{{ t('signStudentLog.fields.miss') }}</span>
            <span v-if="scope.row.signOutStatus === 1">{{
              t('signStudentLog.fields.normal')
            }}</span>
            <span v-if="scope.row.signOutStatus === 2">{{ t('signStudentLog.fields.early') }}</span>
          </template>
        </vxe-column>
        <vxe-column
          :title="t('signStudentLog.fields.signInTime')"
          field="signInTime"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
        <vxe-column
          :title="t('signStudentLog.fields.signOutTime')"
          field="signOutTime"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
      </vxe-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
  </Dialog>
</template>

<script setup lang="ts">
import { CourseSignStudentLogListRespVO, SignStudentLogApi } from '@/api/course/signstudentlog'
import type { VxeTablePropTypes } from 'vxe-table'
import { useAppStore } from '@/store/modules/app'
import { CourseSignLogListRespVO } from '@/api/course/signlog'

/** 课程签到学生记录 列表 */
defineOptions({ name: 'CourseSignStudentLog' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const dialogVisible = ref(false)

const loading = ref(true) // 列表的加载中
const list = ref<CourseSignStudentLogListRespVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  courseId: undefined,
  signLogId: undefined,
  studentName: undefined,
  studentCode: undefined
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

const vxeTableConfig: VxeTablePropTypes.CustomConfig = {
  storage: true,
  mode: 'drawer',
  checkMethod({ column }) {
    return !['seq', 'operator'].includes(column.field)
  }
}

const appStore = useAppStore()
const vxeTableSize = computed(() => appStore.getCurrentSizeVxe)

// 查询列表
const getList = async () => {
  queryParams.signLogId = log.value?.signLogId as any
  loading.value = true
  try {
    const data = await SignStudentLogApi.listSignStudentLog(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

// 搜索按钮操作
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

// 重置按钮操作
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

const log = ref<CourseSignLogListRespVO>()
const open = (row: CourseSignLogListRespVO) => {
  log.value = row
  list.value = []
  total.value = 0
  dialogVisible.value = true
  getList()
}

defineExpose({ open })
</script>
